package com.lagou.mr.test;

import org.apache.hadoop.io.NullWritable;
import org.apache.hadoop.mapreduce.Reducer;

import java.io.IOException;

public class RankReducer extends Reducer<RankBean, NullWritable, RankBean, NullWritable>
{
    //排名
    private int rank = 0;

    @Override
    protected void reduce(RankBean key, Iterable<NullWritable> values, Context context) throws IOException, InterruptedException {
        for (NullWritable value : values) {
            System.out.println("==> reduce.key = " + key + " ; reduce.value = " + value);
            //对所有已排序的bean进行rank赋值，使其内容完整
            key.set_rank(++rank);
            context.write(key, value);
        }
    }
}
